package com.yao2san.runner;

import cn.hutool.system.OsInfo;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class AppCommandLineRunner implements CommandLineRunner {
    private final static String LOCAL_URL = "http://localhost:8086";

    @Override
    public void run(String... args) throws Exception {
        OsInfo osInfo = new OsInfo();
        boolean isWindows = osInfo.isWindows();
        boolean isMac = osInfo.isMac();
        boolean isMacOsX = osInfo.isMacOsX();
        boolean isLinux = osInfo.isLinux();
        Runtime runtime = Runtime.getRuntime();
        if (isWindows) {
            runtime.exec(new String[]{"explorer.exe", LOCAL_URL});
        } else if (isMac || isMacOsX) {
            runtime.exec(new String[]{"open", LOCAL_URL});
        } else if (isLinux) {
            runtime.exec(new String[]{"x-www-browser", LOCAL_URL});
        } else {
            System.err.println("Not support os: " + osInfo.getName());
        }

        System.out.println("Started: "+LOCAL_URL);
    }
}